@echo off

set DEF_FILE=

if "%1"=="" (
if exist constdef.txt (
set DEF_FILE=constdef.txt
) else (
echo usage: 
echo 	%0 definename
goto end
)
) else (
set DEF_FILE=%1
)


set FILE_NAME=noname
set JAVA_PACKAGE=
set AS3_PACKAGE=

for /f "eol=# tokens=1,2 delims==" %%i in (%DEF_FILE%) do (
set str=%%i
setlocal enableDelayedExpansion
if "!str:~0,1!"=="@" (
set str=!str:~1!
if "!str!"=="FILENAME" (
set FILE_NAME=%%j
) else (
if "!str!"=="JAVAPACKAGE" (
set JAVA_PACKAGE=%%j
) else (
if "!str!"=="AS3PACKAGE" (
set AS3_PACKAGE=%%j
)
)
)
)
)

if exist %FILE_NAME%.java del %FILE_NAME%.java
if exist %FILE_NAME%.as del %FILE_NAME%.as

echo package %JAVA_PACKAGE%;>>%FILE_NAME%.java
echo.>>%FILE_NAME%.java
echo public class %FILE_NAME%>>%FILE_NAME%.java
echo {>>%FILE_NAME%.java


echo package %AS3_PACKAGE%>>%FILE_NAME%.as
echo.>>%FILE_NAME%.as
echo public class %FILE_NAME%>>%FILE_NAME%.as
echo {>>%FILE_NAME%.as


for /f "eol=@ tokens=1,2 delims==" %%i in (%DEF_FILE%) do (
echo 	static public final int %%i ^= %%j;>>%FILE_NAME%.java
echo 	static public const %%i:int ^= %%j;>>%FILE_NAME%.as
)

echo }>>%FILE_NAME%.java
echo }>>%FILE_NAME%.as

:end